<?php
/**
 * 显示主题的详细信息
 *
 * @todo
 * @author Judas <judasnow@gmail.com>
 * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
 */
session_start();

include('path.php') ;
require_once( SOJ_ROOT.'/include/function/lib.php');

$tpl = new my_smarty();
$tpl->assign( 'active' , 'questions' );

if ( !empty( $_SESSION['username'] ) ){
	
	$tpl->assign( 'username' , $_SESSION['username'] );	
}

//由GET得到主题号@todo 此处有注入危险
$topic_no = $_GET['topic_no'] ;

try{
	$db = db_connect();
	$topic_process = new topic_process( $db );
	$topic_process->load( 'topic_no' , $topic_no ) ;

	//点击detail页面,会触发view_plus方法
	//其增加ciew_count并保存进数据库中
	$topic_process->plus_view_count();
	$topic_process->save();

	$title = $topic_process->get( 'title' );
	$content = $topic_process->get( 'content' );
	$post_time = $topic_process->get( 'post_time' );
	$view_count = $topic_process->get( 'view_count' );
	$reply_count = $topic_process->get( 'reply_count' );
	$username = $topic_process->get( 'username' );

	$tpl->assign( 'topic_no' , $topic_no ); 
	$tpl->assign( 'title' , $title );
	$tpl->assign( 'content' , $content );
	$tpl->assign( 'post_time' , $post_time );
	$tpl->assign( 'view_count' , $view_count );
	$tpl->assign( 'reply_count' , $reply_count );
	$tpl->assign( 'post_username' , $username );

	//是否有回复
	if( $reply_count > 0 ){
		
		$replys = $topic_process->get_all_reply();
		$tpl->assign( 'replys' , $replys );
	}


}catch( Exception $e ){

	exception_handle( $e ) ;
}

$tpl->display('topic_detail.tpl');

